﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using DBLayer;

namespace BALayer
{
    public class NhaCungCap
    {
        private DAL db = null;
        public NhaCungCap()
        {
            db = new DAL();
        }

        public DataSet DanhSachNhaCungCap()
        {
            // id, tenncc, diachi, sdt
            return db.ExecuteQueryDataSet("select * from NhaCungCap", CommandType.Text, null);
        }

        public bool ThemNhaCungCap(ref string error,String ten,String diachi,String sdt)
        {
            return db.ExecuteNonQuery("uspThemNhaCungCap", CommandType.StoredProcedure, ref error,
                new SqlParameter("@TenNCC", ten),
                new SqlParameter("@Diachi", diachi),
                new SqlParameter("@Sdt", sdt));
        }

        public bool CapNhatNhaCungCap(ref string error,String id,String ten,String diachi,String sdt)
        {
            return db.ExecuteNonQuery("uspCapNhatNhaCungCap", CommandType.StoredProcedure, ref error,
                new SqlParameter("@Id", id),
                new SqlParameter("@TenNCC", ten),
                new SqlParameter("@Diachi", diachi),
                new SqlParameter("@Sdt", sdt));
        }

        public bool XoaNhaCungCap(ref string error,String id)
        {
            return db.ExecuteNonQuery("delete from NhaCungCap where id='" + id + "'", CommandType.Text, ref error, null);
        }
    }
}
